<?php                              

class Glossary extends Controller {

	function Glossary()
	{
		parent::Controller();	
        $this->load->model('glossarymodel'); 
	}     
    
    function index()
    {
                                   
        //load page header
        $this->load->model('pageheadersmodel'); 
        $data["header"] = $this->pageheadersmodel->get_header('glossary');

        //alphabet array  
        $data["alphabet"] = $this->glossarymodel->get_alphabet();

        //glossary of the day
        $this->load->model('glossarymodel'); 
        $data["item"] = $this->glossarymodel->get_glossary_of_the_day();

        //glossary list (popular items)
        $data["list"]["controller"] = 'glossary/view/';
        $data["list"]["items"] = $this->glossarymodel->get_popular_glossary_items();

        //$data["glossary_item"]["Text_Glossary"] = trim_string(strip_tags($data["glossary_item"]["Text_Glossary"]),300,"...");

        $this->load->view('website/default/head', array("document_title" => DOCUMENT_TITLE . "Glossary")); 
        $this->load->view('website/default/header');  
        $this->load->view('website/glossary/glossary', $data);   
        $this->load->view('website/default/footer');   

    }
     
    function view($id = NULL)
    {
     
        //alphabet array  
        $data["alphabet"] = $this->glossarymodel->get_alphabet();

        //glossary item
        $data["item"] = $this->glossarymodel->get_item($id); 
        if (empty($data["item"])) show_404();             


        $this->load->view('website/default/head', array("document_title" => DOCUMENT_TITLE . "Glossary - ".$data["item"]["Title_Glossary"])); 
        $this->load->view('website/default/header');  
        $this->load->view('website/glossary/glossary_detail', $data);   
        $this->load->view('website/default/footer');   

    }
     
    function letter($letter = NULL)
    {

        //alphabet array  
        $data["alphabet"] = $this->glossarymodel->get_alphabet();

        //letter
        $data["letter"] = $letter;

        //list
        $data["list"]["controller"] = 'glossary/view/';
        $data["list"]["items"] = $this->glossarymodel->get_list_by_letter($letter); 
        //if (empty($data["list"])) show_404();             

        $this->load->view('website/default/head', array("document_title" => DOCUMENT_TITLE . "Glossary - ".$letter)); 
        $this->load->view('website/default/header');  
        $this->load->view('website/glossary/glossary_letter', $data);   
        $this->load->view('website/default/footer');   

    }

    function search() {

        $this->load->library('session');
        $this->load->model('searchmodel');

        $search_string = trim($this->input->post('search', TRUE));
        if ($search_string === FALSE)
        show_404();
        
        # put it 
        $this->session->set_userdata('searchword', $search_string); 

        // get search results
        $data["list"]["controller"] = 'glossary/view/';
        $data["list"]["image_folder"] =  base_url().GLOSSARY_IMG_FOLDER;
        $data["list"]["items"] = $this->searchmodel->search_glossary($this->session->userdata('searchword'));

        // alphabet array
        $data["alphabet"] = $this->glossarymodel->get_alphabet();

        $data["search_string"] = $this->session->userdata('searchword');                                                                                 

        $this->load->view('website/default/head', array("document_title" => DOCUMENT_TITLE . "Glossary - Search results for '".$data["search_string"]."'")); 
        $this->load->view('website/default/header');  
        $this->load->view('website/glossary/glossary_search', $data);   
        $this->load->view('website/default/footer');   

    }

}

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */